<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <form>
        <div>用户名:<input type="text" id="userName"></div>
        <div>密&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password" id="userPwd"></div>
        <div>验证码:<input type="text" id="yzm"><span id="yanzhengma"></span></div>
        <div><input id="btn" type="button" value="登录"></div>
    </form>
    <script>
    var userName=document.getElementById("userName");
    var password=document.getElementById("userPwd");
    var yzm=document.getElementById("yzm");
    // yanzhengma.innerHTML=Math.floor( Math.random()*9000 )+1000;//验证码四位数
    var str1="ashduehdue7838455sssd";
    var str="";
    for(var i=0;i<4;i++){
        str+=str1[Math.floor( Math.random()*str1.length )]
    }
    yanzhengma.innerHTML=str;
    var btn=document.getElementById("btn");
    // var yanzhengma=document.getElementById("yanzhengma");
    btn.onclick=function(){
        if(userName.value=="admin"){
            if(password.value=="admin"){
                if(yzm.value==yanzhengma.innerHTML){
                    alert("输入正确")
                }
                else{
                    alert("验证码错误")
                }
            }
            else{
                alert("密码错误")
            }
        }
        else{
            alert("用户名错误")
        }
        
    }
    </script>
</body>
</html>